package app.web.galgame.cgs.netant;

import cn.lily.com.exception.YaconException;
import cn.lily.com.lang.Basic;
import cn.lily.com.lang.DeCode;
import cn.lily.web.page.BusinessPage;
import cn.lily.web.widget.sql.TSqlGrid;
import cn.lily.web.widget.standard.TButton;
import cn.lily.web.widget.standard.TButtonPilot;

public class GamePage extends BusinessPage {
	
	@Override
	public void page_onLoad() throws YaconException {
		
		TSqlGrid yuiNyaGrid = sqlGrid("yuiNyaGrid");
		
		String gameNames = DeCode.decode(this.getAttr("gameName")).toUpperCase();
		String[] names = gameNames.split(",");
		String whereSQL = "";
		for(String name:names){
			whereSQL += " or UPPER(GAME_NAME) like '" + Basic.toWhereLike(name)+"' or UPPER(GAME_NAME_PLUS) like '" + Basic.toWhereLike(name)+"' ";
		}
		
		if(!"".equals(whereSQL)){
			whereSQL = whereSQL.substring(3);
		}
		
		yuiNyaGrid.setDictTable("LEO_GALGAME_INFO_JPS");
		String sqlString = "select RES_ID,GAME_ID,GAME_NAME,GAME_TYP,GAME_LANG,"
				+ "GAME_VISUAL,GAME_SIZE,GAME_SIZE_NUM,GAME_FACTORY,GAME_FIRST,"
				+ "GAME_INTRU,GEME_MEMO,GAME_NAME_PLUS,"
				+ "DISK_ID,GAME_STORE_PATH,GAME_TAGS,"
				+ "to_char(GAME_PRO_TIME,'yyyy-mm-dd') GAME_PRO_TIME,"
				+ "to_char(GAME_CRE_TIME,'yyyy-mm-dd') GAME_CRE_TIME from ${schema}.LEO_GALGAME_INFO_JPS where "+whereSQL;
		yuiNyaGrid.setCommSqlStr(sqlString);
		yuiNyaGrid.setEdit(true);
			
		yuiNyaGrid.createFieldTitle("GAME_NAME").setFieldAlign("center").setDataAlign("center");
		yuiNyaGrid.createFieldTitle("GAME_TYP").setFieldAlign("center").setDataAlign("center");
		yuiNyaGrid.createFieldTitle("GAME_SIZE").setFieldAlign("center").setDataAlign("center");
		yuiNyaGrid.createFieldTitle("GAME_PRO_TIME").setFieldAlign("center").setDataAlign("center");
		yuiNyaGrid.createFieldTitle("GAME_TAGS").setFieldAlign("center").setDataAlign("center");
		yuiNyaGrid.createFieldTitle("RES_ID").setFieldVisible(false);
		yuiNyaGrid.createFieldTitle("GAME_ID").setFieldVisible(false);
		yuiNyaGrid.createFieldTitle("GAME_LANG").setFieldVisible(false);		
		yuiNyaGrid.createFieldTitle("GAME_VISUAL").setFieldVisible(false);		
		yuiNyaGrid.createFieldTitle("GAME_SIZE_NUM").setFieldVisible(false);
		yuiNyaGrid.createFieldTitle("GAME_FACTORY").setFieldVisible(false);
		yuiNyaGrid.createFieldTitle("GAME_FIRST").setFieldVisible(false);		
		yuiNyaGrid.createFieldTitle("GAME_INTRU").setFieldVisible(false);
		yuiNyaGrid.createFieldTitle("GEME_MEMO").setFieldVisible(false);
		yuiNyaGrid.createFieldTitle("GAME_NAME_PLUS").setFieldVisible(false);
		yuiNyaGrid.createFieldTitle("DISK_ID").setFieldVisible(false);
		yuiNyaGrid.createFieldTitle("GAME_STORE_PATH").setFieldVisible(false);	
		yuiNyaGrid.createFieldTitle("GAME_CRE_TIME").setFieldVisible(false);

		TButtonPilot yuiNyaPilot = ButtonPilot("yuiNyaPilot");
		yuiNyaPilot.setPilotIco("/widget/buttonPilot.gif");
		yuiNyaPilot.setPilotText("游戏信息");
		
		
		TButton btn = new TButton("yuiNyaGrid_saveBtn");
		btn.setLabel("确定");
		btn.setIcoPath("glyphicon glyphicon-floppy-saved");
		btn.setViewClick("yuiNyaGrid_saveBtn_click");
		yuiNyaPilot.addButtons(btn);
		
		yuiNyaGrid.setButtonPilot(yuiNyaPilot);
		
		yuiNyaGrid.setTopButtonType("all");
		
		getPage().addElement(yuiNyaGrid);
		
	}
	
	public void refresh() throws YaconException {
		
		TSqlGrid yuiNyaGrid = sqlGrid("yuiNyaGrid");
		
		yuiNyaGrid.setDictTable("LEO_GALGAME_INFO_JPS");
		
		String sqlString = "select RES_ID,GAME_ID,GAME_NAME,GAME_TYP,GAME_LANG,"
				+ "GAME_VISUAL,GAME_SIZE,GAME_SIZE_NUM,GAME_FACTORY,GAME_FIRST,"
				+ "GAME_INTRU,GEME_MEMO,GAME_NAME_PLUS,"
				+ "DISK_ID,GAME_STORE_PATH,GAME_TAGS,"
				+ "to_char(GAME_PRO_TIME,'yyyy-mm-dd') GAME_PRO_TIME,"
				+ "to_char(GAME_CRE_TIME,'yyyy-mm-dd') GAME_CRE_TIME from ${schema}.LEO_GALGAME_INFO_JPS ";
		yuiNyaGrid.setCommSqlStr(sqlString);
		
		this.setSelfMessage(yuiNyaGrid.getDataElement());
		
	}
	
}
